<?php
//----------------------------------
// 圈子模块
// Wanghuabin 2017-10-19
//----------------------------------
namespace Home\Controller;
use Think\Controller;
class CircleController extends CommonController {
    /**
     * [get_order 抓取平台在网贷之家和网贷天眼的排名数据]
     * @param  [type] $wdzj_url   [网贷之家的平台详情页地址]
     * @param  [type] $wdeye_url [网贷天眼的平台详情页地址]
     * @return [type]            [array]
     */
    public function get_order($wdzj_url=0,$wdeye_url=0,$platform_id=0){
        // public function get_order(){
         //采集
       $arr_data = S('arr_data'.$platform_id);
       
        if(!empty($arr_data)){
            return $arr_data;
        }else{
            import("Api.SnoopyApi");
            $Snoopy = new \SnoopyApi();
            //网贷之家排名抓取
            $a = $this->get_file($wdzj_url);
            $str = mb_convert_encoding($a, 'UTF-8', 'UTF-8');//中文编码
            $wdzj_order =  '/<span class=\"col\"><b>(.+?)<\/b>名/is'; //抓取规则 (上线时间)  
            preg_match($wdzj_order , $str , $wdzj_order);
            $wdzj_order = $wdzj_order[1]?$wdzj_order[1]:'-';
            //网贷天眼排名
            $a = $this->get_file($wdeye_url);
            $str = mb_convert_encoding($a, 'UTF-8', 'UTF-8');//中文编码
            $wdty_order =  '/<span>排名:<\/span><strong>(.+?)<\/strong>/is'; //抓取规则 (上线时间)  
            preg_match($wdty_order , $str , $wdty_order);
            $wdty_order = $wdty_order[1]?$wdty_order[1]:'-';

            $arr = array('wdzj_order'=>$wdzj_order,'wdty_order'=>$wdty_order);
            S("arr_data".$platform_id,$arr,array('type'=>'file','expire'=>86400));
            return $arr;
        }
       
    }
	/**
	获取https网页内容
	**/
	   function get_file($url){
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_HEADER, 1);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
            $data = curl_exec($curl);
            curl_close($curl);
            return $data;
    }
    /**
     * [circle_list 平台圈子列表]
     * @return [type] [description]
     */
       public function circle_list(){
        //平台列表
        $map['status']=1;
		$map['id'] = array('neq',4);
        $list = D('Circle')->get_all($map,$field='*');
        $map = array();
        foreach ($list as $k => $v) {
            //加入圈子人数
            $map['platform_id'] = $v['platform_id'];
            $group = M('ImGroup')->where($map)->find();
            $map = array();
            $map['group_id'] = $group['groupid'];
            $map['status'] = 0;
            $group_count = M('ImGroupUser')->where($map)->count();
            $list[$k]['group_count'] = $group_count;
             //深度评测
            $map = array();
            $map['platform_id'] = $v['platform_id'];
            $depth_count = M('OtthAppraisal')->where($map)->count();  //深度评测条数
            $depth_count1 = M('Depth')->where($map)->count();  //深度评测条数
            $list[$k]['depth_count'] = $depth_count;
            //热门点评
			
            $commen_count = M('PlatformCommentary')->where($map)->count();//短评条数
            $annou_count = M('CircleAnnounce')->where($map)->count();//信批评论条数
            $opin_count = M('CircleOpinion')->where($map)->count();//舆情条数
            $total_count = $depth_count1+$commen_count+$annou_count+$opin_count;//总的热评条数
			//echo $depth_count;
            $list[$k]['total_count'] = $total_count;
            //区分热门
             $list[$k]['cricel_leve']=$this->get_cricel_leve($v['platform_id']);
             $hot = $v['is_hot'];
             if($hot==1){
                $hot_list[] = $list[$k];
             }
			 /*
			$pushlist_temp_name = 'temp_'.$k;
			if(S($pushlist_temp_name)){
				$push_list = S($pushlist_temp_name);
			}else{
				$push_list = $this->push_list($v['platform_id']);
				$push_list = $push_list['push_list'][0];
				S($pushlist_temp_name,$push_list,86400);
				//print_r(S('pushlist_temp'));
			}
             */
			  //查询投顾
            $maps = array();
            $maps['_string'] = "FIND_IN_SET(".$v['platform_id'].",push_platform_id)";
			$push_user= D('Recommend')->get_one($maps);
             //echo D('Recommend')->_sql();
             $maps = array();
             $maps['id'] = $push_user['user_id'];
             $push_user['user'] = D('User')->get_one($maps);
             $list[$k]['push_user'] =$push_user;
         }
		 
        $cricle_push_top = R('Ad/get_ad',array('tag'=>'cricle_push_top'));
         //投顾列表
        $map = array();
        $user_id = $_SESSION['user']['id'];
        $map['id'] = $user_id;
        $user = D('User')->get_one($map);
        $map = array();
        if($user){
            $map['user_id'] = $user['referral'];
            $recom = D('Recommend')->get_one($map);
        }

		/*if(S('push_list')){
			$push_list = S('push_list');
		}else{*/ 
			/*$map = array();
			$push_list = D('RecommendPlatform')->where($map)->group('recommend_id')->select();
			foreach ($push_list as $k => $v) {
				$push_list[$k]['user_info'] = $user['nickname'];
				$recommend_id = $v['recommend_id'];
				$map['id'] = $recommend_id;
				$recommen= D('Recommend')->get_one($map);
				if($recommen['id']==$recom['id']){
					$push_list[$k]['is_fans'] = 1;
				}else{
					$push_list[$k]['is_fans'] = 0;
				}
				
				//统计徒弟数量
				
				$where = array();
				$where['referral'] = $recommen['user_id'];
				$push_list[$k]['fans_count']=D('User')->count($where);
				$platform_id_list = explode(',', $recommen['push_plat_id']);
			   // print_r()
				foreach ($platform_id_list as $ke => $va) {
					 $map['id'] = $va;
					 $plat_info = D('Platform')->get_one($map);
					 $push_list[$k]['platform_id_list_arr'][] = $plat_info['name'];
				}
				$push_list[$k]['platform_id_list'] = implode(',', $push_list[$k]['platform_id_list_arr']);
				$map = array();
				$map['referral'] = $recommen['user_id'];
				$push_list[$k]['info'] = $recommen;
				$referral= D('User')->count($map);
				$push_list[$k]['referral'] = $referral;
				$map = array();
				$map['id'] = $recommen['user_id'];
				$userinfo =  D('User')->get_one($map);
				if($userinfo){
					$push_list[$k]['user']=$userinfo;
				}else{
					unset($push_list[$k]);
				}
				

			}
		   
			$sort = array(  
			'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
			'field'     => 'fans_count',       //排序字段  
			); 

			 $arrSort = array();  
			foreach($push_list AS $uniqid => $row){  
				foreach($row AS $key=>$value){  
					$arrSort[$key][$uniqid] = $value;  
				}  
			}  
			if($sort['direction']){  
				array_multisort($arrSort[$sort['field']],constant($sort['direction']),$push_list);  
			}  

			foreach ($push_list as $k => $v) {

				$recommend_id = $v['recommend_id'];
				$arr[$recommend_id] = $push_list[$k];
				
			}
			
			S('push_list',$push_list,86400);*/
		/*}*/ 
        $this->assign('cricle_push_top',$cricle_push_top);
        $this->assign('hot_list',$hot_list);
        $this->assign('push_list',$push_list);
        $this->assign('list',$list);
        $this->display();

    }

    /**
     * [get_cricel_leve 获取平台评级数据]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [array]
     */
    public function get_cricel_leve($platform_id){
        $map['platform_id'] = $platform_id;
        $list = M('PlatformGrade')->where($map)->field('count(*) as count,user_role,colligate')->group('user_role,colligate')->order('count(*) desc,colligate asc')->select();
        $list_all = M('PlatformGrade')->where($map)->field('count(*) as count,user_role,colligate')->group('colligate')->order('count(*) desc,colligate asc')->select();
        $count_user = 0;
        $count = 0;
        $count_push = 0;
       // return $list_all;
        foreach ($list_all as $k => $v) {
            $count = $count+$v['count'];
            $all_grade['all_count']=$count;
            $all_grade[]=$v;

        }
        foreach($list as $k=>$v){
            $role = $v['user_role'];

            if($role==1){
                $count_user = $count_user+$v['count'];
                $usre_grade['all_count']=$count_user;
                $usre_grade[]=$v;
            }else{
                $count_push = $count_push+$v['count'];
                $usre_push['all_count']=$count_push;
                $usre_push[]=$v;
            }
        }
        
        foreach ($usre_grade as $k => $v) {
           $count_percent = sprintf("%.0f",$v['count']/$usre_grade['all_count']*100);
           $usre_grade[$k]['count_percent']=$count_percent;
           $usre_grade[$k]['usre_grade']=$usre_grade['all_count'];
        }
        //unset($usre_grade['all_count']);
        
        foreach ($usre_push as $k => $v) {
           $count_percent = sprintf("%.0f",$v['count']/$usre_push['all_count']*100);
           $usre_push[$k]['count_percent']=$count_percent;
           $usre_push[$k]['usre_grade']=$usre_push['all_count'];
        }
        //unset($usre_push['all_count']);
        foreach ($all_grade as $k => $v) {
           $count_percent = sprintf("%.0f",$v['count']/$all_grade['all_count']*100);
           $all_grade[$k]['count_percent']=$count_percent;
           $all_grade[$k]['usre_grade']=$all_grade['all_count'];
        }
       // unset($usre_push['all_count']);
        $data = array('usre_grade'=>$usre_grade[0],'usre_push'=>$usre_push[0],'all_grade'=>$all_grade[0]);
        return ($data);
    }
    /**
     * [get_cricel_course 获取平台合规进程]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [description]
     */
    public function get_cricel_course($platform_id=1){
        $val_pass = I('get.val');
        if($val_pass){
            $platform_id=I('post.id');
        }
        $map['platform_id'] = $platform_id;
        $info = D('Course')->where($map)->find();
        $count =  count($info)-2;
        $is_good = 0;
        $i = 0;
        foreach ($info as $k => $v) {
            if($k!='id' && $k!='platform_id' && $v==1){
                $is_good = $is_good+1;
            }
             if($k!='id' && $k!='platform_id'){
                switch ($k) {
                    case 'records':
                       $name = "金融局成功备案";
                       $order = 0;
                        break;
                    case 'deposit':
                       $name = "银行存管";
                       $order = 1;
                        break;
                    case 'object':
                       $name = "标的限额";
                       $order = 2;
                        break;
                    case 'risk':
                       $name = "风险提示";
                       $order = 3;
                        break;
                    case 'debt':
                       $name = "禁止债转";
                       $order = 4;
                        break;
                    case 'melt':
                       $name = "禁止自融";
                       $order = 5;
                        break;
                    case 'crowd':
                       $name = "禁止众筹";
                       $order = 6;
                        break;
                    case 'false_sign':
                       $name = "禁止假标";
                       $order = 7;
                        break;
                    case 'capital':
                       $name = "无资金池";
                       $order = 8;
                        break;
                    case 'sign':
                       $name = "禁止拆标";
                       $order = 9;
                        break;
                    case 'borrow':
                       $name = "电子签章";
                        $order = 10;
                        break;
                    case 'pack_asset':
                       $name = "禁止打包资产";
                       $order = 11;
                        break;
                    case 'lending':
                       $name = "禁止放贷";
                       $order = 12;
                        break;
                    case 'offline':
                       $name = "禁止线下推广";
                       $order = 13;
                        break;
                    case 'announce':
                       $name = "信息披露完整";
                       $order = 14;
                        break;
                    case 'obj_info':
                       $name = "标的信息披露";
                       $order = 15;
                        break;    
                    case 'assure':
                       $name = "禁止自担保";
                       $order = 16;
                        break;
                    case 'safety':
                       $name = "信息系统安全评估";
                       $order = 17;
                        break;
                    // case 'sell':
                    //    $name = "禁止代销";
                    //     break;
                    case 'brenk':
                       $name = "无承诺保本保息";
                       $order = 18;
                        break;

                   
                    case 'product':
                       $name = "不代销理财产品";
                       $order = 19;
                        break;
                    
                    case 'business':
                       $name = "网贷中介营业执照";
                       $order = 20;
                        break;
                   
                    case 'telecom':
                       $name = "互金专属ICP经营许可证";
                       $order = 21;
                        break;
                    default:
                        # code...
                        break;
                }
                if($v==0){
                    $val = 1;
                }elseif ($v==1) {
                    $val = 2;
                }elseif ($v==2) {
                    $val = 3;
                }
                $arr[$i]['name'] = $name;
                $arr[$i]['val'] = $val;
                $arr[$i]['order'] = $order;
                $i = $i+1;
            }

        }
       $sort = array(  
        'direction' => 'SORT_ASC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
        'field'     => 'order',       //排序字段  
        ); 

         $arrSort = array();  
        foreach($arr AS $uniqid => $row){  
            foreach($row AS $key=>$value){  
                $arrSort[$key][$uniqid] = $value;  
            }  
        }  
        if($sort['direction']){
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$arr);  
        }  

      //  print_r($arr);

        if($val_pass){
            $is_good = sprintf("%.0f",$is_good/$count*100);
            $cricel_course = array('info'=>$arr,'is_good'=>$is_good);
            $this->assign('cricel_course',$cricel_course);
            $content = $this->fetch('process_item');
            $this->ajaxReturn(array('content'=>$content));
        }else{
            $is_good = sprintf("%.0f",$is_good/$count*100);
            $cricel_course = array('info'=>$arr,'is_good'=>$is_good);
            return($cricel_course);
        }
    }

    /**
     * [push_list 平台投顾列表 按推荐成功的投资者数量排序]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [array]
     */
    public function push_list($platform_id){

       
        $user_id = $_SESSION['user']['id'];
        $map['id'] = $user_id;
        $user = D('User')->get_one($map);
        // return(1);d
        if($user){
            $map = array();
            $map['user_id'] = $user['referral'];
            $recom = D('Recommend')->get_one($map);
        }

         $map = array();
        $map['platform_id'] = $platform_id;
        $push_list = D('RecommendPlatform')->get_all($map,$field="*",$page=0,$pagenum=3);
        $push_count = D('RecommendPlatform')->count($map);
        foreach ($push_list as $k => $v) {
            $map=array();
            $recommend_id = $v['recommend_id'];
            $map['id'] = $recommend_id;
            $recommen= D('Recommend')->get_one($map);
             if($v['recommend_id']==$recom['id']){
                $push_list[$k]['is_fans'] = 1;
            }else{
                $push_list[$k]['is_fans'] = 0;
            }

            $map = array();
            $map['id'] = $recommen['user_id'];
            $push_list[$k]['user']= D('User')->get_one($map);
            //统计推手在该平台投资人
            $map = array();
            $map['referral'] = $recommen['user_id'];
            $push_list[$k]['info'] = $recommen;
            $referral= D('User')->get_all($map);
            $tz_count = 0;
            foreach ($referral as $key => $value) {
                //print_r($value);
                $map = array();
                $map['user_id'] = $value['id'];
                $map['platform_id'] = $platform_id;
                $r = D('UserObject')->get_one($map);
                if($r){
                    ;
                     $tz_count = $tz_count+1;
                }
            }
            $push_list[$k]['tz_count'] =$tz_count;
            //红包
            $push_list[$k]['packet'] = R('Packet/get_redpacket',array('user_id'=>$recommen['user_id'],'platform_id'=>$platform_id));
        }


        $sort = array(  
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
        'field'     => 'tz_count',       //排序字段  
        ); 

         $arrSort = array();  
        foreach($push_list AS $uniqid => $row){  
            foreach($row AS $key=>$value){  
                $arrSort[$key][$uniqid] = $value;  
            }  
        }  
        if($sort['direction']){  
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$push_list);  
        }  
        $push_list = array_slice($push_list,0,7);
        $push_list = array('push_list'=>$push_list,'push_count'=>$push_count,'user_info'=>$user['nickname']);
        return $push_list;
    }


    /**
     * [get_appraisal 获取平台官方测评]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [array]
     */
    public function get_appraisal($platform_id){
        $map['platform_id'] = $platform_id;
        $map['house_id'] = array('neq',574);
        $video_app = M('VideoAppraisal')->where($map)->order('add_time desc')->select();
        if($video_app){
            foreach($video_app as $k => $v) {
                $platform[$k]['add_time'] = date('Y-m-d',$v['add_time']);
                $house_id= $v['house_id'];
                $map = array();
                $map['id'] = $house_id;
                $video_app[$k]['video_info'] = D('Video')->get_one($map);
                //查询播放量和时间
                $maps = array();
                $maps = $video_app[$k]['video_info']['video_id'];
                $field = 'push_play,play_amount,add_time';
                $v_play= D('VideoHouse')->get_one($maps,$field);
                $video_app[$k]['video_info']['play_count'] = $v_play['push_play']+$v_play['play_amount'];
                if(!$house_id){
                    $map = array();
                    $map['id'] = $v['news_id'];
                    $video_app[$k]['news_info'] = D('NewsHouse')->get_one($map,$field="pic");
                    $video_app[$k]['house_id'] =0;
                   // echo D('NewsHouse')->_sql();
                }
                if($v['house_id'] == 574){
                    // unset($video_app[$k]);
                    $map = array();
                    $map['id'] = $v['news_id'];
                    $video_app[$k]['news_info'] = D('NewsHouse')->get_one($map,$field="pic");
                    $video_app[$k]['house_id'] =0;
                }

            }
        } 
        return ($video_app);

    }

    /**
     * [get_evaluate 获取平台评价信息]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [array]
     */
    public function get_evaluate($platform_id=1){
		
        $val = I('post.val');
        if($val){
            $platform_id = I('post.platform_id');
            $page = I('post.p');
            $pagenum = 5;
			$page = ($page)*$pagenum;
			$pagenum = $page+$pagenum-1; 
        }else{
            $page=0;
            $pagenum=5;
        }
        //$platform_id = 8;
        //获取短评
        $map['platform_id'] = $platform_id;
        $map['user_role'] = 1;
        $map['status'] = 1;
        $pcomm1= D('PlatformCommentary')->get_all_page($map);
        $map['user_role'] = 2;
        $pcomm2= D('PlatformCommentary')->get_all($map);
      // echo D('PlatformCommentary')->_sql();
        $pcomm=array_merge($pcomm1,$pcomm2);
        $userid = $_SESSION['user']['id'];

        $map = array();
        $map['platform_id'] = $platform_id;
        $map['status'] = 1;
        $map['user_role'] = 1;
        $opinion = D('CircleOpinion')->get_all($map);
        foreach ($opinion as $k => $v) {
            $v['type']=2;
            $pcomm[]= $v;

        }

        foreach ($pcomm as $k => $v) {
            if($v['type']!=2){
                $v['tag'] = explode(',',$v['tag']);
                $v['type']=1;
            }
           
            $map['id'] = $v['user_id'];
            $v['user'] =D('User')->get_one($map);
            $map = array();
            $map['user_id'] = $v['user_id'];
			$map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);

            $add_time = $v['add_time'];
            //判断是否点赞
            if($userid){
                $where['id_user'] = $userid;
                if($type==2){
                     $where['type'] =8;
                }else{
                     $where['type'] = 6;
                }

               
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $long = time()-$add_time;
           
            if($long<60){
                $v['add_date'] = $long."秒前";
            }else if($long<3600){
                $v['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $v['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $v['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $v['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                 $v['add_date'] = "刚刚";
            }


            if($v['user_role']==1){

                $user_evaluate[] = $v;
            }elseif($v['user_role']==2){
                $v['type']=1;
                $push_evaluate[]= $v;
            }

        }

        //合并推手的深度评测
        $map = array();
        $map['platform_id'] = $platform_id;
        $map['status'] = 1;
        $depth = D('Depth')->get_all($map);
        foreach ($depth as $k => $v) {
            $v['type']=2;
             if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 7;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $map = array();
            $map['user_id'] = $v['user_id'];
			$map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);
             $push_evaluate[]= $v;

        }
        //合并信批
        $map = array();
        $map['platform_id'] = $platform_id;
        $map['status'] = 1;
        $announce = D('CircleAnnounce')->get_all($map);
        foreach ($announce as $k => $v) {
            $v['type']=3;
            
             if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 9;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $map = array();
            $map['user_id'] = $v['user_id'];
			$map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);
            $push_evaluate[]= $v;
        }
        //合并舆情解读
        $map = array();
        $map['platform_id'] = $platform_id;
        $map['status'] = 1;
        $map['user_role'] = 2;
        $opinion = D('CircleOpinion')->get_all($map);
        foreach ($opinion as $k => $v) {
            $v['type']=4;
            
            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 8;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $map = array();
            $map['user_id'] = $v['user_id'];
            $map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);
			
            $push_evaluate[]= $v;

        }
        foreach ($push_evaluate as $k => $v) {
            
            $map = array();
            $map['id'] = $v['user_id'];
            $push_evaluate[$k]['user'] =D('User')->get_one($map);
            $add_time = $v['add_time'];

            $long = time()-$add_time;
           
            if($long<60){
                $push_evaluate[$k]['add_date'] = $long."秒前";
            }else if($long<3600){
                $push_evaluate[$k]['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $push_evaluate[$k]['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $push_evaluate[$k]['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $push_evaluate[$k]['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                $push_evaluate[$k]['add_date'] = "刚刚";
            }
        }
        $all_evaluate = array_merge($push_evaluate,$user_evaluate);
		$sort = array(
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序
        'field'     => 'add_time',       //排序字段
        );

        $arrSort = array();
        foreach($all_evaluate AS $uniqid => $row){
            foreach($row AS $key=>$value){
                $arrSort[$key][$uniqid] = $value;
            }
        }
        if($sort['direction']){
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$all_evaluate);
        }
		
	//echo $page."***".$pagenum;
        $all_evaluate=array_slice($all_evaluate,$page,$pagenum);
       // $user_evaluate=array_slice($user_evaluate,$page,$pagenum);
        //时间排序
         //时间排序
     
        $evaluate_list['user_evaluate'] = $user_evaluate;
        $evaluate_list['all_evaluate'] = $all_evaluate;
       // 
        //return $evaluate_list['push_evaluate'];
        if($val){
            //print_r($evaluate_list);
            if($val==1){
                    if($evaluate_list['user_evaluate']){
                        $this->assign('evaluate',$evaluate_list);
                        $content = $this->fetch('info_user_item');
                    }else{
                        $content=0;
                    }
                  
            }elseif ($val==2) {
                 
                    $this->assign('evaluate',$evaluate_list);
                    $content = $this->fetch('info_tg_item');
            }
             $this->ajaxReturn(array('content'=>$content));
        }else{
            return($evaluate_list);
        }
    }


    public function get_otth_appraisal($platform_id){
        $map['platform_id'] = $platform_id;
        $list = M('OtthAppraisal')->where($map)->limit(0,3)->select();
        foreach ($list as $k => $v) {
            $map = array();
            $map['id'] = $v['news_id'];
           $list[$k]['news_info'] = D('News')->get_one($map,$field="id,title,");
           $add_time = $v['add_time'];
            $long = time()-$add_time;
           
            if($long<60){
                $list[$k]['add_date'] = $long."秒前";
            }else if($long<3600){
                $list[$k]['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $list[$k]['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $list[$k]['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $list[$k]['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                 $list[$k]['add_date'] = "刚刚";
            }
        }
        return ($list);
    }
    /**
     * 第三方测评列表
     */
    public function otth_list(){
        $platform_id = I('get.id');
        $list = $this->get_otth_appraisal($platform_id);
        $this->assign('list',$list);
        $this->display();
    }

    /**
     * [get_program_tag 获取平台圈子基础信息]
     * @param  [type] $platform_id [description]
     * @return [type]              [description]
     */
    public function get_program_circle($platform_id){
        $map['platform_id'] = $platform_id;
        $info = D('Circle')->get_one($map);
        return $info;
    }

    public function circle_info(){
        
        $platform_id = I('get.id');
        //获取圈子基础信息
        $circle_info = $this->get_program_circle($platform_id);
         $platform_id = I('get.id');
        //获取圈子基础信息
        $circle_info = $this->get_program_circle($platform_id);
        $map['id'] = $circle_info['platform_id'];
        $platform_info = D('Platform')->get_one($map);
        $circle_info['platform_name'] = $platform_info['name'];
       
        //print_r($circle_info);die;
        //排名数据
        
        $wdeye_url = $circle_info['eye_url'];
        $wdzj_url = $circle_info['home_url'];
        $plat_order = $this->get_order($wdzj_url,$wdeye_url,$platform_id);
        //print_r($plat_order);
        //评级数据
        
        $cricel_leve = $this->get_cricel_leve($platform_id);
        //合规进程
        $cricel_course = $this->get_cricel_course($platform_id);
        //投顾列表
		//明星投顾
         $maps = array();
		// $maps['push_platform_id'] = $platform_id;
		 //$maps['push_platform_id']  = array('FIND_IN_SET',$platform_id);
		 $maps['_string'] = "FIND_IN_SET(".$platform_id.",push_platform_id)";
		 $push_user= D('Recommend')->get_one($maps);
		 //echo D('Recommend')->_sql();
		 $maps = array();
		 $maps['id'] = $push_user['user_id'];
		 $push_user['user'] = D('User')->get_one($maps);
		 $push_user['packet'] = R('Packet/get_redpacket',array('user_id'=>$push_user['user']['id'],'platform_id'=>$platform_id));  

		
        $push_list = $this->push_list($platform_id);
        //print_r($push_list);
        //8号金融街测评
        $jie_appraisal = $this->get_appraisal($platform_id);
        //print_r($jie_appraisal);
        $evaluate = $this->get_evaluate($platform_id);
        //平台合规进程
        $cricel_course = $this->get_cricel_course($platform_id);
        $otth_appraisal = $this->get_otth_appraisal($platform_id);
        foreach ($otth_appraisal as $k => $v) {
           $otth_appraisal[$k]['add_data_day'] = date('d',$v['add_time']);
           $otth_appraisal[$k]['add_data_month'] = strtoupper(date('M',$v['add_time']));
        }

        //投资方案
        $map = array();
        $map['platform_id'] = $platform_id;
        $list = D('PlatformScheme')->get_all($map);
        
       // print_r($otth_appraisal);
        $this->assign('list',$list);
        $this->assign('push_user',$push_user);
        $this->assign('otth_appraisal',$otth_appraisal);
        $this->assign('cricel_course',$cricel_course);
        $this->assign('evaluate',$evaluate);
        $this->assign('jie_appraisal',$jie_appraisal);
        $this->assign('push_list',$push_list);
        $this->assign('cricel_course',$cricel_course);
        $this->assign('cricel_leve',$cricel_leve);
        $this->assign('plat_order',$plat_order);
        $this->assign('circle_info',$circle_info);
        $this->display();
    }

    /**
     * [grade 提交平台综合评价]
     * @return [type] [description]
     */
    public function grade(){
        $user_id = $_SESSION['user']['id'];
        $map['id'] = $user_id;
        $userinfo = D('User')->get_one($map);
        $user_role = $userinfo['role'];
        if($user_role==2){
            $role = 2;
        }else{
            $role = 1;
        }
        $platform_id = I('post.platform_id');
        $colligate = I('post.colligate');
        $is_invest = I('post.is_invest');
        $map = array();
        $map['platform_id'] = $platform_id;
        $map['user_id'] = $user_id;
        $r = D('PlatformGrade')->get_one($map);
        if($r){
            $map = array();
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $data['colligate'] = $colligate;
            $data['user_role'] = $role;
            $data['is_invest'] = $is_invest;
            $res = D('PlatformGrade')->edit($map,$data);
        }else{
            $data['user_id'] = $user_id;
            $data['user_role'] = $role;
            $data['colligate'] = $colligate;
            $data['platform_id'] = $platform_id;
            $data['is_invest'] = $is_invest;
            $data['add_time'] = time();
            $res = D('PlatformGrade')->add($data);
        }
        if($res){
            $data = array('err'=>0,'msg'=>"成功！");
        }else{
            $data = array('err'=>1,'msg'=>"失败！");

        }
        $this->ajaxReturn($data);
    }
    /**
     * [add_commentary 添加平台短评]
     */
    public function short_commentary(){
        if(IS_POST){
            $edit = I('post.edit');
            if($edit){
                $user_id = $_SESSION['user']['id'];
                $info_id = I('post.info_id');
                $map['id'] = $info_id;
                $info = D('PlatformCommentary')->get_one($map);
                if($info['user_id']==$user_id){
                    $datas['id'] =$info_id;
                    $tag = I('post.tag');
                    $datas['tag'] = implode(',',$tag);
                    $datas['evaluate'] = I('post.evaluate');
                    $datas['platform_id'] = I('post.platform_id');
                    $map = array();
                    $map['id'] = $info_id;
                    $r = D('PlatformCommentary')->edit($map,$datas);
                    if($r){
                        $data = array('err'=>0,'msg'=>"编辑成功");
                    }else{
                        $data = array('err'=>1,'msg'=>"您未修改任何内容");
                    }
                    $this->ajaxReturn($data);
                }else{
                    $data = array('err'=>2,'msg'=>"非法操作");
                    $this->ajaxReturn($data);
                }
               
            }
            $user_id = $_SESSION['user']['id'];
            $user_role = $_SESSION['user']['role'];
            $card_status = $_SESSION['user']['card_status'];
            if($card_status==0){
                $data = array('err'=>3,'msg'=>"您未实名认证提交失败！");
                $this->ajaxReturn($data);
            }
            $tag = I('post.tag');
            $data['tag'] = implode(',',$tag);
            $data['evaluate'] = I('post.evaluate');
            $data['platform_id'] = I('post.platform_id');
            $data['user_id'] =$user_id;
            if($user_role==2){
                $data['user_role']=2;
            }else{
                $data['user_role']=1;
            }
            $data['status']=1;
            $data['add_time']=time();
            $r = D('PlatformCommentary')->add($data);
           //echo  D('PlatformCommentary')->_sql();
            if($r){
                $data = array('err'=>0,'msg'=>"提交成功！");
            }else{
                $data = array('err'=>1,'msg'=>"提交失败！");
            }
            $this->ajaxReturn($data);
        }else{
             $edit = I('get.edit');
            if($edit==1){
                $info_id = I('get.info_id');
                $map['id'] = $info_id;
                $info = D('PlatformCommentary')->get_one($map);
                $info['tag'] = explode(',',$info['tag']);
                //print_r($info);
                $this->assign('edit',1);
                $this->assign('info',$info);

            }

            $map = array();
            $user_id = $_SESSION['user']['id'];
            $platform_id =I('get.id');
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $r = D('PlatformGrade')->get_one($map);
            $this->assign('colligate',$r['colligate']);
            $this->assign('is_invest',$r['is_invest']);
            $this->display();
        }
       
       
    }
    /**
     * [commentary_info 短评详情]
     * @return [type] [description]
     */
    public function commentary_info(){
        $id = I('get.id');
        $platform_id = I('get.platform_id');
        $userid = $_SESSION['user']['id'];
        $map['id'] = $id;
        $info = D('PlatformCommentary')->get_one($map);
        //print_r($info);
        $map = array();
        $map['id'] = $info['user_id'];
        $info['user'] = D('User')->get_one($map);
        $info['tag'] = explode(',',$info['tag']);
        $map = array();
        $map['id'] = $platform_id;
        $platform_info = D('Platform')->get_one($map);
        $info['platform_name'] = $platform_info['name'];
        
        if($userid){
            $where['id_user'] = $userid;
            $where['type'] = 6;
            $where['id_target'] = $info['id'];
            $praise = D('Praise')->get_one($where);
            if($praise){
                $info['is_praise'] = 1;
                }else{
                    $info['is_praise'] = 0;
                }
            }else{
                    $info['is_praise'] = 0;
            }

            $long = time()-$info['add_time'];
            if($long<60){
                $info['add_date'] = $long."秒前";
            }else if($long<3600){
                $info['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $info['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $info['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $info['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
            }else if($long=0){
                 $info['add_date'] = "刚刚";
            }




         //查询用户综合评价
         $map = array();
         $map['user_id'] = $info['user_id'];
         $map['platform_id'] = $platform_id;
         $grade = D('PlatformGrade')->get_one($map);
        //   echo D('PlatformGrade')->_sql();
        // print_r($grade);die;
        //查询评论
        $map = array();
        $map['id_target'] = $id;
        $map['type'] = 4;
        $map['p_id'] =0;
        $comment = D('Comment')->get_all($map);
       
        foreach ($comment as $k => $v) {
             $long = time()-$v['add_time'];
            if($long<60){
                $comment[$k]['add_date'] = $long."秒前";
            }else if($long<3600){
                $comment[$k]['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $comment[$k]['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $comment[$k]['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $comment[$k]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
            }else if($long=0){
                $comment[$k]['add_date'] = "刚刚";
            }

            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 3;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
             if($praise){
                    $comment[$k]['is_praise'] = 1;
                }else{
                    $comment[$k]['is_praise'] = 0;
                }
            }else{
                    $comment[$k]['is_praise'] = 0;
            }


            $map = array();
            $map['id'] = $v['user_id'];
            $comment[$k]['user'] = D('User')->get_one($map);
            $map = array();
            $map['p_id'] =$v['id'];
            $kid = D('Comment')->get_all($map);
                foreach ($kid as $ke => $va) {
                    $map = array();
                    $map['id'] = $va['user_id'];
                    $kid[$ke]['user'] = D('User')->get_one($map);
                    $long = time()-$va['add_time'];
                    if($long<60){
                        $kid[$ke]['add_date'] = $long."秒前";
                    }else if($long<3600){
                        $kid[$ke]['add_date']= ceil($long/60)."分钟前";
                    }else if($long>3600 && $long<86400){
                        $kid[$ke]['add_date']= ceil($long/3600)."小时前";
                    }else if($long>86400 && $long<259200){
                        $kid[$ke]['add_date'] = ceil($long/86400)."天前";
                    }else if($long>259200){
                        $kid[$ke]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                    }else if($long=0){
                        $kid[$ke]['add_date'] = "刚刚";
                    }


                }
            $comment[$k]['kid'] = $kid;
        }

        //print_r($info);
        $this->assign('grade',$grade);
        $this->assign('comment',$comment);
        $this->assign('info',$info);
        $this->display();
    }
    
    //圈子舆情解读
    public function circle_opinion() {
        if(IS_POST) {
            $edit = I('post.edit');
            if($edit){
                $info_id = I('post.info_id');
                $map['id'] = $info_id;
                $o_info = D('CircleOpinion')->get_one($map);
                if($o_info['user_id']==$_SESSION['user']['id']){
                    $map = array();
                    $maps['id'] = $info_id;
                    $datas['content'] = I('post.content');
                    $r = D('CircleOpinion')->edit($maps,$datas);
                        if($r){
                            $data = array('err'=>0,'msg'=>"编辑成功！");
                        }else{
                            $data = array('err'=>1,'msg'=>"编辑失败！");
                        }
                     $this->ajaxReturn($data);
                }else{
                    $data = array('err'=>1,'msg'=>"非法操作");
                    $this->ajaxReturn($data);
                }
            }
            $user_id = $_SESSION['user']['id'];
            $user_role = $_SESSION['user']['role'];
            $card_status = $_SESSION['user']['card_status'];
            if($card_status==0){
                $data = array('err'=>1,'msg'=>"您未实名认证提交失败！");
                $this->ajaxReturn($data);
            }
            $postdata = I('post.');
            if($user_role==2){
                $postdata['user_role']=2;
            }else{
                $postdata['user_role']=1;
            }
            $postdata['platform_id'] = I('post.platform_id');
            $postdata['user_id'] = $user_id;
            $postdata['add_time'] = time();
            $r = D('CircleOpinion')->add($postdata);
            if($r){
                $data = array('err'=>0,'msg'=>"提交成功！");
            }else{
                $data = array('err'=>1,'msg'=>"提交失败！");
            }
            $this->ajaxReturn($data);
        } else {
            $edit = I('get.edit');
            if($edit){
                $info_id = I('get.info_id');
                $platform_id = I('get.id');
                $map['id'] = $info_id;
                $circle_info = D('CircleOpinion')->get_one($map);
                $this->assign('edit',1);
                $this->assign('circle_info',$circle_info);
            }
            $map = array();
            $user_id = $_SESSION['user']['id'];
            $platform_id =I('get.id');
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $r = D('PlatformGrade')->get_one($map);
        //    print_r($r);die;
            $this->assign('colligate',$r['colligate']);
            $this->assign('is_invest',$r['is_invest']);
            $this->display();
        }
    }


    /**
     * [circle_opinion_info 舆情详情]
     * @return [type] [description]
     */
    public function circle_opinion_info(){
        $id = I('get.id');
        $platform_id = I('get.platform_id');
        $userid = $_SESSION['user']['id'];
        $map['id'] = $id;
        $info = D('CircleOpinion')->get_one($map);
        $map = array();
        $map['id'] = $info['user_id'];
        $info['user'] = D('User')->get_one($map);
        $info['tag'] = explode(',',$info['tag']);

        if($userid){
            $where['id_user'] = $userid;
            $where['type'] = 8;
            $where['id_target'] = $info['id'];
            $praise = D('Praise')->get_one($where);
            //echo D('Praise')->_sql();
            if($praise){
                $info['is_praise'] = 1;
                }else{
                    $info['is_praise'] = 0;
                }
            }else{
                    $info['is_praise'] = 0;
            }

            $long = time()-$info['add_time'];
            if($long<60){
                $info['add_date'] = $long."秒前";
            }else if($long<3600){
                $info['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $info['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $info['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $info['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
            }else if($long=0){
                 $info['add_date'] = "刚刚";
            }




         //查询用户综合评价
         $map = array();
         $map['user_id'] = $info['user_id'];
         $map['platform_id'] = $platform_id;
         $grade = D('PlatformGrade')->get_one($map);
        //   echo D('PlatformGrade')->_sql();
        // print_r($grade);die;
        //查询评论
        $map = array();
        $map['id_target'] = $id;
        $map['type'] = 6;
        $map['p_id'] =0;
        $comment = D('Comment')->get_all($map);
       
        foreach ($comment as $k => $v) {
             $long = time()-$v['add_time'];
            if($long<60){
                $comment[$k]['add_date'] = $long."秒前";
            }else if($long<3600){
                $comment[$k]['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $comment[$k]['add_date']= ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $comment[$k]['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $comment[$k]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
            }else if($long=0){
                $comment[$k]['add_date'] = "刚刚";
            }

            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 3;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
             if($praise){
                    $comment[$k]['is_praise'] = 1;
                }else{
                    $comment[$k]['is_praise'] = 0;
                }
            }else{
                    $comment[$k]['is_praise'] = 0;
            }


            $map = array();
            $map['id'] = $v['user_id'];
            $comment[$k]['user'] = D('User')->get_one($map);
            $map = array();
            $map['p_id'] =$v['id'];
            $kid = D('Comment')->get_all($map);
                foreach ($kid as $ke => $va) {
                    $map = array();
                    $map['id'] = $va['user_id'];
                    $kid[$ke]['user'] = D('User')->get_one($map);
                    //echo 
                    $long = time()-$va['add_time'];
                    if($long<60){
                         $kid[$ke]['add_date'] = $long."秒前";
                    }else if($long<3600){
                         $kid[$ke]['add_date'] = ceil($long/60)."分钟前";
                    }else if($long>3600 && $long<86400){
                         $kid[$ke]['add_date'] = ceil($long/3600)."小时前";
                    }else if($long>86400 && $long<259200){
                         $kid[$ke]['add_date'] = ceil($long/86400)."天前";
                    }else if($long>259200){
                         $kid[$ke]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                    }else if($long=0){
                         $kid[$ke]['add_date'] = "刚刚";
                    }


                }
            $comment[$k]['kid'] = $kid;
        }
	

        //print_r($comment);
        $this->assign('grade',$grade);
        $this->assign('comment',$comment);
        $this->assign('info',$info);
        $this->display();
    }

    /**
     * [depth 提交深度测评]
     * @return [type] [description]
     */
    public function depth(){
        if(IS_POST){
			$user_id = $_SESSION['user']['id'];
            $edit = I('post.edit');
            if($edit){
                $info_id = I('post.info_id');
                $map['id'] = $info_id;
                $d_info = D('Depth')->get_one($map);
                if($d_info['user_id']==$_SESSION['user']['id']){
                    $maps['id'] = $info_id;
                    $datas = I('post.');
                    unset($datas['temporary']);
                    unset($datas['info_id']);
                    unset($datas['edit']);
                    $res = D('Depth')->edit($maps,$datas);
                    if($res){
                        $arr = array('err'=>0,'msg'=>'编辑成功');
                    }else{
                        $arr = array('err'=>1,'msg'=>'编辑失败');
                    }
                     $this->ajaxReturn($arr);
                }else{
                    $data = array('err'=>1,'msg'=>"非法操作");
                    $this->ajaxReturn($data);
                }
               
            }
            $temporary = I('post.temporary');
            $platform_id = I('post.platform_id');
            if($temporary){
                $filed = I('post.filed');
                $map['user_id'] = $user_id;
                $map['platform_id'] = $platform_id;
                $map['status'] = 0;
                $r = D('Depth')->get_one($map);
                if($r){
                    $data[$filed] = I('post.name');
                    $map = array();
                    $map['user_id'] = $user_id;
                    $map['platform_id'] = $platform_id;
                    $map['status'] = 0;
                    $res = D('Depth')->edit($map,$data);

                    if($res){
                        $arr = array('err'=>0,'msg'=>'暂存成功');
                    }else{
                        $arr = array('err'=>1,'msg'=>'暂存失败');
                    }
                }else{
                    $data = array();
                    $data[$filed] = I('post.name');
                    $data['user_id'] = $user_id;
                    $data['platform_id'] = $platform_id;
                    $data['add_time'] = $add_time;
                    $map['status'] = 0;
                    $res = D('Depth')->add($data);
                    if($res){
                        $arr = array('err'=>0,'msg'=>'暂存成功');
                    }else{
                        $arr = array('err'=>1,'msg'=>'暂存失败');
                    }
                }
                $this->ajaxReturn($arr);
            }else{

                $postdata = I('post.');
                unset($postdata['temporary']);
                $postdata['status'] = 1;
                $map = array();
                $map['user_id'] = $user_id;
                $map['platform_id'] = $platform_id;
                $map['status'] = 0;
                $r = D('Depth')->get_one($map);
                $postdata['add_time'] = time();
                $postdata['user_id'] =$user_id;
				//print_r($postdata);die; 
                if($r){
                    $map = array();
                    $map['user_id'] = $user_id;
                    $map['platform_id'] = $platform_id;
                    $map['status'] = 0;
                    $res = D('Depth')->edit($map,$postdata);
                    if($res){
                        $arr = array('err'=>0,'msg'=>'发表成功');
                    }else{
                        $arr = array('err'=>1,'msg'=>'发表失败');
                    }
                }else{
                    $res = D('Depth')->add($postdata);
                    if($res){
                        $arr = array('err'=>0,'msg'=>'发表成功');
                    }else{
                        $arr = array('err'=>1,'msg'=>'发表失败');
                    }
                }
                
                $this->ajaxReturn($arr);
            }
        }else{
             $edit = I('get.edit');
                if($edit){
                    $info_id = I('get.info_id');
                    $map['id'] = $info_id;
                    $depth_info = D('Depth')->get_one($map);
                    $this->assign('depth_info',$depth_info);
                    $this->assign('edit',1);
                }
            $map = array();
            $platform_id = I('get.id');
            $map['platform_id'] = $platform_id;
            $info = D('PlatformParameters')->get_one($map);
            $user_id = $_SESSION['user']['id'];
            $platform_id =I('get.id');
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $r = D('PlatformGrade')->get_one($map);

            $map = array();
            $map['user_id'] = $_SESSION['user']['id'];
            $map['platform_id'] = $platform_id;
            $map['status'] = 0;
            $res = D('Depth')->get_one($map);

            //管理团队
            $map['platform_id'] = $platform_id;
            $plat_team = M('PlatformTeam')->where($map)->select();

            //股权结构
            $plat_stock = M('PlatformStock')->where($map)->select();

            //资产类型
            $platform_assets = M('PlatformAssets')->where($map)->select();
            //舆情
            $platform_opinion = M('PlatformOpinion')->where($map)->select();
            $opinion_count = M('PlatformOpinion')->where($map)->count();
            $this->assign('opinion_count',$opinion_count);
            $this->assign('platform_opinion',$platform_opinion);
            $this->assign('platform_assets',$platform_assets);
            $this->assign('plat_stock',$plat_stock);
            $this->assign('plat_team',$plat_team);
            $this->assign('info',$info);
            $this->assign('r',$res);
            $this->assign('colligate',$r['colligate']);
            $this->assign('is_invest',$r['is_invest']);
            $this->display();
        }
       
    }

    /**
     * [depth_info 深度测评详情]
     * @return [type] [description]
     */
    public function depth_info(){

            $platform_id = I('get.platform_id');
            $map['platform_id'] = $platform_id;
            $info = D('PlatformParameters')->get_one($map);
           // echo D('PlatformParameters')->_sql();
            $user_id = $_SESSION['user']['id'];
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $r = D('PlatformGrade')->get_one($map);

            $map = array();
            $map['user_id'] = $_SESSION['user']['id'];
            $map['platform_id'] = $platform_id;
            $map['status'] = 0;
            $res = D('Depth')->get_one($map);

            //管理团队
            $map['platform_id'] = $platform_id;
            $plat_team = M('PlatformTeam')->where($map)->select();

            //股权结构
             
            $plat_stock = M('PlatformStock')->where($map)->select();
            //资产类型
            $platform_assets = M('PlatformAssets')->where($map)->select();
            //舆情
            $platform_opinion = M('PlatformOpinion')->where($map)->select();
            $opinion_count = M('PlatformOpinion')->where($map)->count();

            //解读
            $map = array();
            $map['id'] = I('get.id');
            $r = D('Depth')->get_one($map);
            $user_id = $r['user_id'];
            $map['id'] = $user_id;
            $r['user'] =D('User')->get_one($map);
            $long = time()-$r['add_time'];
           
            if($long<60){
                $r['add_date'] = $long."秒前";
            }else if($long<3600){
                $r['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $r['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $r['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $r['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                $r['add_date'] = "刚刚";
            }
              //查询用户综合评价
             $map = array();
             $map['user_id'] =  $user_id;
             $map['platform_id'] = $platform_id;
             $grade = D('PlatformGrade')->get_one($map);
            //判断点赞
            $userid = $_SESSION['user']['id'];
            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 7;
                $where['id_target'] = I('get.id');
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $r['is_praise'] = 1;
                }else{
                    $r['is_praise'] = 0;
                }
            }else{
                    $r['is_praise'] = 0;
            }

                //查询评论
            $map = array();
            $map['id_target'] = I('get.id');
            $map['type'] = 5;
            $map['p_id'] =0;
            $comment = D('Comment')->get_all($map);
            
            foreach ($comment as $k => $v) {
                 $long = time()-$v['add_time'];
                if($long<60){
                    $comment[$k]['add_date'] = $long."秒前";
                }else if($long<3600){
                    $comment[$k]['add_date'] = ceil($long/60)."分钟前";
                }else if($long>3600 && $long<86400){
                    $comment[$k]['add_date'] = ceil($long/3600)."小时前";
                }else if($long>86400 && $long<259200){
                    $comment[$k]['add_date'] = ceil($long/86400)."天前";
                }else if($long>259200){
                    $comment[$k]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                }else if($long=0){
                    $comment[$k]['add_date'] = "刚刚";
            }

            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 3;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
             if($praise){
                    $comment[$k]['is_praise'] = 1;
                }else{
                    $comment[$k]['is_praise'] = 0;
                }
            }else{
                    $comment[$k]['is_praise'] = 0;
            }


            $map = array();
            $map['id'] = $v['user_id'];
            $comment[$k]['user'] = D('User')->get_one($map);
            $map = array();
            $map['p_id'] =$v['id'];
            $kid = D('Comment')->get_all($map);
                foreach ($kid as $ke => $va) {
                    $map = array();
                    $map['id'] = $va['user_id'];
                    $kid[$ke]['user'] = D('User')->get_one($map);
                    //echo 
                    $long = time()-$va['add_time'];
                    if($long<60){
                         $kid[$ke]['add_date'] = $long."秒前";
                    }else if($long<3600){
                         $kid[$ke]['add_date'] = ceil($long/60)."分钟前";
                    }else if($long>3600 && $long<86400){
                         $kid[$ke]['add_date'] = ceil($long/3600)."小时前";
                    }else if($long>86400 && $long<259200){
                         $kid[$ke]['add_date'] = ceil($long/86400)."天前";
                    }else if($long>259200){
                         $kid[$ke]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                    }else if($long=0){
                         $kid[$ke]['add_date'] = "刚刚";
                    }


                }
                    $comment[$k]['kid'] = $kid;
                }

			$map = array();
            $map['id'] = $platform_id;
            $platform_name = D('Platform')->get_one($map);
            $platform_name = $platform_name['name'];
            //print_r($comment);die;
            $this->assign('platform_name',$platform_name);
            $this->assign('comment',$comment);
            $this->assign('res',$r);
            $this->assign('grade',$grade);
            $this->assign('opinion_count',$opinion_count);
            $this->assign('platform_opinion',$platform_opinion);
            $this->assign('platform_assets',$platform_assets);
            $this->assign('plat_stock',$plat_stock);
            $this->assign('plat_team',$plat_team);
            $this->assign('info',$info);
            $this->assign('r',$res);
            $this->assign('colligate',$r['colligate']);
            $this->display();
    }

    /**
     * [infoann 信息披露]
     * @return [type] [description]
     */
    public function infoann(){
        if(IS_POST){
            $edit = I('post.edit');
            if($edit == 1){
                $info_id = I('post.info_id');
                $map['id'] = $info_id;
                $f_info = D('CircleAnnounce')->get_one($map);
                if($f_info['user_id']==$_SESSION['user']['id']){
                    $datas['announce'] = I('post.announce');
                    $maps['id'] = $info_id;
                    $r = D('CircleAnnounce')->edit($maps,$datas);
                    if($r){
                        $arr = array('err'=>0,'msg'=>'编辑成功');
                    }else{
                        $arr = array('err'=>1,'msg'=>'编辑失败');
                    }
                    $this->ajaxReturn($arr);
                }else{
                    $arr = array('err'=>0,'msg'=>'非法操作');
                    $this->ajaxReturn($arr);
                }
                
            }
            $postdata['user_id'] = $_SESSION['user']['id'];
            $postdata['platform_id'] = I('post.platform_id');
            $postdata['announce'] = I('post.announce');
            $postdata['status'] = 1;
            $postdata['add_time'] = time();
            $r = D('CircleAnnounce')->add($postdata);
            if($r){
                $arr = array('err'=>0,'msg'=>'发表成功');
            }else{
                $arr = array('err'=>1,'msg'=>'发表失败');
            }
            $this->ajaxReturn($arr);
        }else{
            $edit = I('get.edit');
            if($edit){
                $info_id = I('get.info_id');
                $map['id'] = $info_id;
                $circle_info = D('CircleAnnounce')->get_one($map);
                $this->assign('circle_info',$circle_info);
                $this->assign('edit',1);
            }
            $map = array();
            $id = I('get.id');
            $map['platform_id'] = $id;
            $infos = D('CircleInfoann')->get_one($map);
            $map = array();
            $map['id'] = $id;
            $platform_info = D('Platform')->get_one($map);
            $infos['platform_name'] = $platform_info['name'];
            $map = array();
            $map['platform_id'] = $id;
            $platform_report = M('PlatformReport')->where($map)->order('id desc')->find(); 
            foreach ($infos as $k => $v) {
                //平台基础信息
                $info['basics']['plat_name'] = $infos['plat_name'];//平台全称及简称 
                $info['basics']['plat_add'] = $infos['plat_add'];//平台注册地址  
                $info['basics']['capital'] = $infos['capital'];//平台注册资本和实缴资本 
                $info['basics']['online'] = $infos['online'];//平台成立时间
                $info['basics']['legal'] = $infos['legal'];//平台法定代表人
                $info['basics']['treaty'] = $infos['treaty'];//注册协议模板 
                $info['basics']['branch'] = $infos['branch'];//平台及其各分支机构经营场所
                $info['basics']['deposit'] = $infos['deposit'];//客户资金存管情况
                $info['basics']['perm'] = $infos['perm'];//相应电信业务经营许可信息
                $info['basics']['evals'] = $infos['eval'];//信息安全评测认证信息
                $info['basics']['scope'] = $infos['scope'];//平台经营范围 
                $info['basics']['records'] = $infos['records'];//地方金融监管部门备案登记信息
                $info['basics']['insure'] = $infos['insure'];//与保险机构，担保机构等合作情况
                $info['basics']['recordss'] = $infos['recordss'];//网站备案
                $info['basics']['deposit_report'] = $infos['deposit_report'];//存管报告
                $info['basics']['contact'] = $infos['contact'];//联系方式
                //平台治理信息
                $info['govern']['tissue'] = $infos['tissue'];//组织机构 
                $info['govern']['control'] = $infos['control'];//实际控制人持股名单
                $info['govern']['director'] = $infos['director'];//董事，监事
                //平台财务
                $info['finance']['audit'] = $infos['audit'];//审计报告意见
                $info['finance']['financing'] = $infos['financing'];//重要融资信息 
                $info['finance']['accountant'] = $infos['accountant'];//会计报表 
                //运营信息
                $info['operate']['trade'] = $infos['trade'];//交易金额 
                $info['operate']['stroke'] = $infos['stroke'];//交易总笔数
                $info['operate']['borrow'] = $infos['borrow'];//借款人总数 
                $info['operate']['invest'] = $infos['invest'];//投资人总数 
                $info['operate']['compen'] = $infos['compen'];//代偿金额
                $info['operate']['exceed'] = $infos['exceed'];//逾期金额
                $info['operate']['limit'] = $infos['limit'];//项目逾期率
                $info['operate']['limit_num'] = $infos['limit_num'];//逾期项目数 
                $info['operate']['pre_borrow'] = $infos['pre_borrow'];//人均累计借款金额
                $info['operate']['pre_invest'] = $infos['pre_invest'];//人均累计投资金额
                $info['operate']['single_finan'] = $infos['single_finan'];//单笔均融资金额 
                $info['operate']['one_balance'] = $infos['one_balance'];//最大单户借款余额占比   
                $info['operate']['ten_balance'] = $infos['ten_balance'];//最大10户借款余额占比
                $info['operate']['one_invest'] = $infos['one_invest'];//最大单户投资余额占比
                $info['operate']['ten_invest'] = $infos['ten_invest'];//最大十户投资余额占比
                $info['operate']['history'] = $infos['history'];//历史逾期项目数
                $info['operate']['add_borrow'] = $infos['add_borrow'];//人均累计借款金额
                $info['operate']['add_invest'] = $infos['add_invest'];//人均累计投资额度
                $info['operate']['mean_invest'] = $infos['mean_invest'];//单笔均融资金额
                //项目简介
                
                $info['obj']['project'] = $infos['project'];    //项目简介
                $info['obj']['guarantee'] = $infos['guarantee'];//还款保障措施
                $info['obj']['risk'] = $infos['risk'];//项目风险提示
                $info['obj']['useing'] = $infos['use'];//借款用途
                $info['obj']['cost'] = $infos['cost'];//相关费用 
                $info['obj']['contract'] = $infos['contract'];//合同模板 
                $info['obj']['project_info'] = $infos['project_info'];//项目基础信息
                
            }
            $basics_i = 0;
            $basics_count = count($info['basics']);
            foreach ($info['basics'] as $k => $v) {
                if($v==1){
                    $basics_i = $basics_i+1;
                }
                $info['basics']['v'] = ceil($basics_i/$basics_count*100);
            }

            $finance_i = 0;
            $finance_count = count($info['finance']);
            foreach ($info['finance'] as $k => $v) {
                if($v==1){
                    $finance_i = $finance_i+1;
                }
                $info['finance']['v'] = ceil($finance_i/$finance_count*100);
            }

            $govern_i = 0;
            $govern_count = count($info['govern']);
            foreach ($info['govern'] as $k => $v) {
                if($v==1){
                    $govern_i = $govern_i+1;
                }
                $info['govern']['v'] = ceil($govern_i/$govern_count*100);
            }

            $operate_i = 0;
            $operate_count = count($info['operate']);
            foreach ($info['operate'] as $k => $v) {
                if($v==1){
                    $operate_i = $operate_i+1;
                }
                $info['operate']['v'] = ceil($operate_i/$operate_count*100);
            }

            $obj_i = 0;
            $obj_count = count($info['obj']);
            foreach ($info['obj'] as $k => $v) {
                if($v==1){
                    $obj_i = $obj_i+1;
                }
                $info['obj']['v'] = ceil($obj_i/$obj_count*100);
            }

            $infos_i = 0;
            $infos_count = count($infos);
            foreach ($infos as $k => $v) {
                if($v==1){
                    $infos_i = $infos_i+1;
                }
                $infos['v'] = ceil($infos_i/$infos_count*100);
            }

            $map = array();
            $user_id = $_SESSION['user']['id'];
            $platform_id =I('get.id');
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $r = D('PlatformGrade')->get_one($map);
            $this->assign('platform_report',$platform_report);
            $this->assign('colligate',$r['colligate']);
            $this->assign('is_invest',$r['is_invest']);
            $this->assign('info',$info);
            $this->assign('infos',$infos);
            $this->display();
        }
       
    }

    /**
     * [infoann_info 信批详情]
     * @return [type] [description]
     */
     public function infoann_info(){

            $id = I('get.platform_id');
            $map['platform_id'] = $id;
            $infos = D('CircleInfoann')->get_one($map);
            $map = array();
            $map['id'] = $id;
            $platform_info = D('Platform')->get_one($map);
            $infos['platform_name'] = $platform_info['name'];
            $map = array();
            $map['platform_id'] = $id;
            $platform_report = M('PlatformReport')->where($map)->order('id desc')->find(); 
          
            foreach ($infos as $k => $v) {
                //平台基础信息
                $info['basics']['plat_name'] = $infos['plat_name'];//平台全称及简称 
                $info['basics']['plat_add'] = $infos['plat_add'];//平台注册地址  
                $info['basics']['capital'] = $infos['capital'];//平台注册资本和实缴资本 
                $info['basics']['online'] = $infos['online'];//平台成立时间
                $info['basics']['legal'] = $infos['legal'];//平台法定代表人
                $info['basics']['treaty'] = $infos['treaty'];//注册协议模板 
                $info['basics']['branch'] = $infos['branch'];//平台及其各分支机构经营场所
                $info['basics']['deposit'] = $infos['deposit'];//客户资金存管情况
                $info['basics']['perm'] = $infos['perm'];//相应电信业务经营许可信息
                $info['basics']['evals'] = $infos['eval'];//信息安全评测认证信息
                $info['basics']['scope'] = $infos['scope'];//平台经营范围 
                $info['basics']['records'] = $infos['records'];//地方金融监管部门备案登记信息
                $info['basics']['insure'] = $infos['insure'];//与保险机构，担保机构等合作情况
                //平台治理信息
                $info['govern']['tissue'] = $infos['tissue'];//组织机构 
                $info['govern']['control'] = $infos['control'];//实际控制人持股名单
                $info['govern']['director'] = $infos['director'];//董事，监事
                //平台财务
                $info['finance']['audit'] = $infos['audit'];//审计报告意见
                $info['finance']['financing'] = $infos['financing'];//重要融资信息 
                //运营信息
                $info['operate']['trade'] = $infos['trade'];//交易金额 
                $info['operate']['stroke'] = $infos['stroke'];//交易总笔数
                $info['operate']['borrow'] = $infos['borrow'];//借款人总数 
                $info['operate']['invest'] = $infos['invest'];//投资人总数 
                $info['operate']['compen'] = $infos['compen'];//代偿金额
                $info['operate']['exceed'] = $infos['exceed'];//逾期金额
                $info['operate']['limit'] = $infos['limit'];//项目逾期率
                $info['operate']['limit_num'] = $infos['limit_num'];//逾期项目数 
                $info['operate']['pre_borrow'] = $infos['pre_borrow'];//人均累计借款金额
                $info['operate']['pre_invest'] = $infos['pre_invest'];//人均累计投资金额
                $info['operate']['single_finan'] = $infos['single_finan'];//单笔均融资金额 
                $info['operate']['one_balance'] = $infos['one_balance'];//最大单户借款余额占比   
                $info['operate']['ten_balance'] = $infos['ten_balance'];//最大10户借款余额占比
                $info['operate']['one_invest'] = $infos['one_invest'];//最大单户投资余额占比
                $info['operate']['ten_invest'] = $infos['ten_invest'];//最大十户投资余额占比
                $info['operate']['history'] = $infos['history'];//历史逾期项目数
                $info['operate']['add_borrow'] = $infos['add_borrow'];//人均累计借款金额
                $info['operate']['add_invest'] = $infos['add_invest'];//人均累计投资额度
                $info['operate']['mean_invest'] = $infos['mean_invest'];//单笔均融资金额
                //项目简介
                
                $info['obj']['project'] = $infos['project'];    //项目简介
                $info['obj']['guarantee'] = $infos['guarantee'];//还款保障措施
                $info['obj']['risk'] = $infos['risk'];//项目风险提示
                $info['obj']['useing'] = $infos['use'];//借款用途
                $info['obj']['cost'] = $infos['cost'];//相关费用 
                $info['obj']['contract'] = $infos['contract'];//合同模板 
                $info['obj']['project_info'] = $infos['project_info'];//项目基础信息
                
            }
            $basics_i = 0;
            $basics_count = count($info['basics']);
            foreach ($info['basics'] as $k => $v) {
                if($v==1){
                    $basics_i = $basics_i+1;
                }
                $info['basics']['v'] = ceil($basics_i/$basics_count*100);
            }

            $finance_i = 0;
            $finance_count = count($info['finance']);
            foreach ($info['finance'] as $k => $v) {
                if($v==1){
                    $finance_i = $finance_i+1;
                }
                $info['finance']['v'] = ceil($finance_i/$finance_count*100);
            }

            $govern_i = 0;
            $govern_count = count($info['govern']);
            foreach ($info['govern'] as $k => $v) {
                if($v==1){
                    $govern_i = $govern_i+1;
                }
                $info['govern']['v'] = ceil($govern_i/$govern_count*100);
            }

            $operate_i = 0;
            $operate_count = count($info['operate']);
            foreach ($info['operate'] as $k => $v) {
                if($v==1){
                    $operate_i = $operate_i+1;
                }
                $info['operate']['v'] = ceil($operate_i/$operate_count*100);
            }

            $obj_i = 0;
            $obj_count = count($info['obj']);
            foreach ($info['obj'] as $k => $v) {
                if($v==1){
                    $obj_i = $obj_i+1;
                }
                $info['obj']['v'] = ceil($obj_i/$obj_count*100);
            }

            $infos_i = 0;
            $infos_count = count($infos);
            foreach ($infos as $k => $v) {
                if($v==1){
                    $infos_i = $infos_i+1;
                }
                $infos['v'] = ceil($infos_i/$infos_count*100);
            }
             //解读
            $map = array();
            $map['id'] = I('get.id');
            $r = D('CircleAnnounce')->get_one($map);
            $user_id = $r['user_id'];
            $map['id'] = $user_id;
            $r['user'] =D('User')->get_one($map);
            $long = time()-$r['add_time'];
          // echo $long;
            if($long<60){
                $r['add_date'] = $long."秒前";
            }else if($long<3600){
                $r['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $r['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $r['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $r['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                $r['add_date'] = "刚刚";
            }
            //判断点赞
            $userid = $_SESSION['user']['id'];
            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 9;
                $where['id_target'] = I('get.id');
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $r['is_praise'] = 1;
                }else{
                    $r['is_praise'] = 0;
                }
            }else{
                    $r['is_praise'] = 0;
            }

                //查询评论
            $map = array();
            $map['id_target'] = I('get.id');
            $map['type'] = 7;
            $map['p_id'] =0;
            $comment = D('Comment')->get_all($map);
            foreach ($comment as $k => $v) {
                 $long = time()-$v['add_time'];
                if($long<60){
                    $comment[$k]['add_date'] = $long."秒前";
                }else if($long<3600){
                    $comment[$k]['add_date'] = ceil($long/60)."分钟前";
                }else if($long>3600 && $long<86400){
                    $comment[$k]['add_date'] = ceil($long/3600)."小时前";
                }else if($long>86400 && $long<259200){
                    $comment[$k]['add_date'] = ceil($long/86400)."天前";
                }else if($long>259200){
                    $comment[$k]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                }else if($long=0){
                    $comment[$k]['add_date'] = "刚刚";
            }

            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 3;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
             if($praise){
                    $comment[$k]['is_praise'] = 1;
                }else{
                    $comment[$k]['is_praise'] = 0;
                }
            }else{
                    $comment[$k]['is_praise'] = 0;
            }


            $map = array();
            $map['id'] = $v['user_id'];
            $comment[$k]['user'] = D('User')->get_one($map);
            $map = array();
            $map['p_id'] =$v['id'];
            $kid = D('Comment')->get_all($map);
                foreach ($kid as $ke => $va) {
                    $map = array();
                    $map['id'] = $va['user_id'];
                    $kid[$ke]['user'] = D('User')->get_one($map);
                    //echo 
                    $long = time()-$va['add_time'];
                    if($long<60){
                         $kid[$ke]['add_date'] = $long."秒前";
                    }else if($long<3600){
                         $kid[$ke]['add_date'] = ceil($long/60)."分钟前";
                    }else if($long>3600 && $long<86400){
                         $kid[$ke]['add_date'] = ceil($long/3600)."小时前";
                    }else if($long>86400 && $long<259200){
                         $kid[$ke]['add_date'] = ceil($long/86400)."天前";
                    }else if($long>259200){
                         $kid[$ke]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                    }else if($long=0){
                         $kid[$ke]['add_date'] = "刚刚";
                    }


                }
                    $comment[$k]['kid'] = $kid;
                }
            //查询用户综合评价
            $platform_id =I('get.platform_id');
            $map = array();
            $map['user_id'] = $r['user_id'];
            $map['platform_id'] = $platform_id;
            $grade = D('PlatformGrade')->get_one($map);
            $map = array();
            $user_id = $_SESSION['user']['id'];
            //print_r($r);die;
			
            $this->assign('platform_report',$platform_report);
            $this->assign('comment',$comment);
            $this->assign('res',$r);
            $this->assign('grade',$grade);
            $this->assign('colligate',$grade['colligate']);
            $this->assign('info',$info);
            $this->assign('infos',$infos);
            $this->display();
        
       
    }

    /**
     * [correction 补充，纠错]
     * @return [type] [description]
     */
    public function correction(){
        $postdata = I('post.');
        $postdata['user_id'] = $_SESSION['user']['id'];
        $postdata['add_time'] = time();
        $r = D('PlatformCorrection')->data($postdata)->add();
		
        if($r){
			if($postdata['type']==1){
				 $data = array('err'=>0,'msg'=>"您填写的纠错信息已经提交，我们将会尽快审核！");
			}else{
				 $data = array('err'=>0,'msg'=>"您填写的参数补充建议已经提交，我们将会尽快审核！");
			}
           
        }else{
            $data = array('err'=>1,'msg'=>"提交失败！");
        }
        $this->ajaxReturn($data);
    }
    
        //师傅列表
    public function master_list(){
        $userid = $_SESSION['user']['id'];
        $map['user_id'] = $userid;
        $map['status'] = 1;
        $r = D('AdviserFollow')->get_all($map);
        foreach ($r as $k => $v) {
            $map=array();
            $map['id'] = $v['recommend_id'];
            $recommend = D('Recommend')->get_one($map);
            $map = array();
            $map['id'] = $recommend['user_id'];
            $r[$k]['user'] = D('User')->get_one($map);
        }
        $this->assign('r',$r);
        $this->display();
        //print_r($r);
    }

    //徒弟列表
    public function pupil_list(){
        $userid = $_SESSION['user']['id'];
        $map['referral'] = $userid; 
        $list = D('User')->get_all($map);
        $this->assign('r',$list);
        $this->display();
    }

    //设置红包
    public function set_pack(){
        $platform_id = I('get.platform_id');
        $userid = $_SESSION['user']['id'];
		if(!$userid){
			header("location:/Home/User/login"); 
		}
        if(IS_POST){
            $scheme_id = I('post.scheme_id');
            $user_award = I('post.user_award');
            $push_award = I('post.push_award');
            $set_res =  R('Packet/set_redpacket',array('platform_id'=>$platform_id,'scheme_id'=>$scheme_id,'userid'=>$userid,'user_award'=>$user_award,'push_award'=>$push_award));
            $this->ajaxReturn($set_res);
        }else{
            $packet_list = R('Packet/get_redpacket',array('userid'=>$userid,'platform_id'=>$platform_id));
            $this->assign('packet_list',$packet_list);
            $this->display();
        }
    }
	
    public function rank_list(){
        if(IS_POST){
            $p_list = M('RankPlatform')->where()->select();
            $now_time = M('Rank')->Max('add_time');
            foreach ($p_list as $k => $v) {
                $map['plat_id'] = $v['id'];
                $map['add_time'] = $now_time;
                $rank_info = M('Rank')->where($map)->find();
                $p_list[$k]['home_rank'] = $rank_info['home_rank'];
                $p_list[$k]['eye_rank'] = $rank_info['eye_rank'];
                $p_list[$k]['rong_rank'] = $rank_info['rong_rank'];
            }
            $val = I('post.val');
            $o_id = I('post.o_id');
            if($val==1){
                $field = 'home_rank';
            }elseif($val==2){
                $field = 'eye_rank';
            }elseif($val==3){
                $field = 'rong_rank';
            }

            if($o_id==1){
                $direction="SORT_ASC";
            }elseif($o_id==2){
                $direction="SORT_DESC";
            }
               $sort = array(
                'direction' => $direction, //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序
                'field'     =>$field,       //排序字段
                );

                $arrSort = array();
                foreach($p_list AS $uniqid => $row){
                    foreach($row AS $key=>$value){
                        $arrSort[$key][$uniqid] = $value;
                    }
                }
                if($sort['direction']){
                    array_multisort($arrSort[$sort['field']],constant($sort['direction']),$p_list);
                }



            // print_r($p_list);
            $this->ajaxReturn($p_list);
        }else{
			 $ad_list = R('Ad/get_ad',array('tag'=>'wx_ranking_list'));
             $now_time = M('Rank')->Max('add_time');
             $push_date = date('Y-m-d',$now_time);
             $this->assign('push_date',$push_date);
			 $this->assign('ad_list',$ad_list);
            $this->display();
        }
       
    }


    public function rank_info(){
        $id =I('get.id');
        $map['id'] = $id;
        $p_info = M('RankPlatform')->where($map)->find();
        if(!$p_info['sys_id']){

         $id = 8;
        $info = D('Platform')->get_one($map);
        $map = array();
        $map['platform_id'] = $id;
        $info['circle'] = D('Circle')->get_one($map);
        $info['cricel_leve']= R('Circle/get_cricel_leve',array('platform_id'=>$id));


           
            $map = array();
            $map['platform_id'] = $id;
            $list = D('PlatformScheme')->get_all($map);
           // print_r($list);
            foreach ($list as $k => $v) {
                if($v['deadline_unit']==0){
                    $tz_award= $v['start_amount']*$v['yields']/100/12*$v['deadline'];
                    $tz_all_award=sprintf("%.2f", $tz_award+$v['user_award']);
                    $tz_award = sprintf("%.2f",$tz_award);
                    $list[$k]['tz_award'] = $tz_award;
                    $list[$k]['tz_all_award']  = $tz_all_award;
                    $event_years=  sprintf("%.2f",$tz_all_award/$v['start_amount']*12/$v['deadline'])*100;
                    $list[$k]['event_years'] = $event_years;
                    if($event_years>$event_years_top){
                        
                        $event_years_top = $event_years;
                    }
                }else{
                    $tz_award= $v['start_amount']*$v['yields']/100/360*$v['deadline'];
                    $tz_all_award=sprintf("%.2f", $tz_award+$v['user_award']);
                    $tz_award = sprintf("%.2f",$tz_award);
                    $list[$k]['tz_award'] = $tz_award;
                    $list[$k]['tz_all_award']  = $tz_all_award;
                    $event_years=  sprintf("%.2f",$tz_all_award/$v['start_amount']*360/$v['deadline'])*100;
                    $list[$k]['event_years'] = $event_years;
                    if($event_years>$event_years_top){
                        $event_years_top = $event_years;
                    }
                }
                
            }

        }
        if($p_info){
            $map = array();
            $map['plat_id'] = $p_info['id'];
            $rank_info = M('Rank')->where($map)->select();
        }

        foreach ($rank_info as $k => $v) {
            $date[] = date('Y-m',$v['add_time']);
            $home_rank[]=$v['home_rank'];
            $eye_rank[]=$v['eye_rank'];
            $rong_rank[]=$v['rong_rank'];
        }
        //print_r($list);
        $date = json_encode($date);
        $home_rank = json_encode($home_rank);
        $eye_rank = json_encode($eye_rank);
        $rong_rank = json_encode($rong_rank);
        $this->assign('home_rank',$home_rank);
        $this->assign('eye_rank',$eye_rank);
        $this->assign('rong_rank',$rong_rank);
        $this->assign('date',$date);
        $this->assign('p_info',$p_info);
        $this->assign('list',$list);
        $this->assign('info',$info);
		$this->display();
   
	}
}